//package com.xinxing.learning.crud.batch.transactional;
//
//import org.apache.ibatis.executor.statement.StatementHandler;
//import org.apache.ibatis.plugin.Interceptor;
//import org.apache.ibatis.plugin.Intercepts;
//import org.apache.ibatis.plugin.Invocation;
//import org.apache.ibatis.plugin.Signature;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.stereotype.Component;
//
//import java.lang.reflect.Method;
//import java.sql.Connection;
//import java.util.Objects;
//import java.util.Properties;
//
//@ConditionalOnProperty(name = "isRollback", havingValue = "true")
//@Intercepts({
//        @Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})
//})
//@Component
//public class ConnectionInterceptor implements Interceptor {
//    @Override
//    public Object intercept(Invocation invocation) throws Throwable {
//        Connection connection = CurrentConnectionHolder.getConnection();
//        if (Objects.nonNull(connection)) {
//            Method method = invocation.getMethod();
//            Object target = invocation.getTarget();
//            return method.invoke(target, connection, 50000);
//        } else {
//            return invocation.proceed();
//        }
//    }
//
//    @Override
//    public Object plugin(Object target) {
//        return Interceptor.super.plugin(target);
//    }
//
//    @Override
//    public void setProperties(Properties properties) {
//        Interceptor.super.setProperties(properties);
//    }
//}
